package algorithm.dynamic_programming;

public class NumberTriangle {

    public static int dynamic(int[][] a, int h, int l) {
        int i, j;
        for (i = h - 2; i >= 0; i--) {
            for (j = 0; j <= i; j++) {
                a[i][j] += Math.max(a[i + 1][j], a[i + 1][j + 1]);
            }
        }
        return a[0][0];
    }

    public static int avarice(int[][] a, int h, int l) {
        int result = 0;
        int i, j = 0;
        for (i = 0; i < h; i++) {
            if (i == 0){
                result = a[i][0];
                continue;
            }
            if (a[i][j] >= a[i][j + 1]){
                result += a[i][j];
            }else {
                result += a[i][j + 1];
                j ++ ;
            }
        }
        return result;
    }
}
